import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import city from './modules/city.js'
import cinemaArea from './modules/cinemaArea.js'
import dataListTimeStamp from './modules/dataListTimeStamp.js'
import login from './modules/login.js'

Vue.use(Vuex)

export default new Vuex.Store({
  // vuex持久化
  plugins: [createPersistedState({
    storage: window.sessionStorage // 默认存储在localStorage里面

    // 未使用modules之前
    // reducer: (state) => {
    //   return {
    //     // 需要进行持久化的数据
    //     cityId: state.cityId,
    //     cityName: state.cityName
    //   }
    // }
  })],

  state: { // 公共状态
    isTabbarShow: true
  },
  mutations: { // 改变公共状态的方法，只支持同步
    showTabbar (state) {
      state.isTabbarShow = true
    },
    hideTabbar (state) {
      state.isTabbarShow = false
    }
  },
  actions: { // 支持异步和同步

  },
  modules: {
    city,
    cinemaArea,
    dataListTimeStamp,
    login
  }
})
